//
//  SetViewController.m
//  ReadMoon
//
//  Created by 殷殷明静 on 16/9/21.
//  Copyright © 2016年 YMJ. All rights reserved.
//

#import "SetViewController.h"
#import "SetTableViewCell.h"
#import "YMJMacro_h.h"

#define COLOR_ICON [UIColor colorWithRed:255 / 256.0 green:22 / 256.0 blue:63 / 256.0 alpha:1]
@interface SetViewController ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic, strong) UIButton *backBtn;
@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) NSMutableArray *dataArray;
@property (nonatomic, strong) UIButton *loginBtn;
@end

@implementation SetViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self initNavigationLeftButton];
    self.automaticallyAdjustsScrollViewInsets = NO;
    self.view.backgroundColor = [UIColor whiteColor];
//    self.edgesForExtendedLayout = 0;
    [self createView];
    [self createData];
}
- (void)createData {
    _dataArray = [NSMutableArray arrayWithObjects:@"字体大小",@"推送通知",@"版本更新", @"版本信息", nil];
}
- (void)createView {
    _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 64, SCREEN_WIDTH, 180) style:UITableViewStylePlain];
    [self.view addSubview:_tableView];
    [self.tableView registerNib:[UINib nibWithNibName:@"SetTableViewCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"1"];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    /*退出登录*/
    if (_isLogin) {
        _loginBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [self.view addSubview:_loginBtn];
        _loginBtn.frame = CGRectMake(0, 0, SCREEN_WIDTH - 20, 30);
        _loginBtn.center = CGPointMake(SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2 );
        _loginBtn.layer.cornerRadius = 15;
        _loginBtn.backgroundColor = COLOR_ICON;
        [_loginBtn setTitle:@"退出登录" forState:0];
        _loginBtn.titleLabel.font = [UIFont systemFontOfSize:13];
        [_loginBtn setTitleColor:[UIColor whiteColor] forState:0];
        [_loginBtn addTarget:self action:@selector(goToLoginViewController) forControlEvents:UIControlEventTouchUpInside];
    }
    
    
}
- (void)goToLoginViewController {
    [self.delegate exitLogin:NO];
    [self.navigationController popViewControllerAnimated:YES];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 4;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    SetTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"1"];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.fontLabel.text = _dataArray[indexPath.row];
    cell.isOpen.hidden = YES;
    if (indexPath.row == 1) {
        cell.sizeLabel.hidden = YES;
        cell.isOpen.hidden = NO;
        cell.goAhead.hidden = YES;
    } else if (indexPath.row > 1) {
        cell.sizeLabel.hidden = YES;
    }
    return cell;
}
- (void)initNavigationLeftButton {
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 50, 25)];
    ;
    label.text = @"设置";
    label.font = [UIFont systemFontOfSize:13];
    self.navigationItem.titleView = label;
    _backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.view addSubview:_backBtn];
    _backBtn.frame = CGRectMake(20, 20, 15, 15);
    [_backBtn setBackgroundImage:[UIImage imageNamed:@"Icon_jiantou"] forState:0];
    [_backBtn addTarget:self action:@selector(backToMyViewController) forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:_backBtn];
}

// 返回之前页面
- (void)backToMyViewController {

    [self.navigationController popViewControllerAnimated:YES];

}
- (void)viewWillAppear:(BOOL)animated {

    [super viewWillAppear:animated];
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
